﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TruongVu.Business;

namespace TruongVuWebsite.Admin
{
    public partial class NewsManagement : System.Web.UI.Page
    {
        private TruongVu.Business.News _news;
        protected void Page_Load(object sender, EventArgs e)
        {
            this._news = new TruongVu.Business.News();
            this.NewsListGridView.DataSource = this._news.GetNews();
            this.NewsListGridView.DataBind();
        }

        protected void NewsListGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            List<TruongVu.Data.New> news = this.NewsListGridView.DataSource as List<TruongVu.Data.New>;
            if (news != null && news.Count > e.RowIndex)
            {
                this._news.DeleteNews(news[e.RowIndex].ID);
                news.RemoveAt(e.RowIndex);
                this.NewsListGridView.DataBind();
            }
        }

        protected void NewsListGridView_RowEditing(object sender, GridViewEditEventArgs e)
        {
            List<TruongVu.Data.New> news = this.NewsListGridView.DataSource as List<TruongVu.Data.New>;
            if (news != null && news.Count > e.NewEditIndex)
            {
                Response.Redirect("NewsDetail.aspx?ID=" + news[e.NewEditIndex].ID);
            }
        }
    }
}